package com.uuah.server.config.i18n;

import java.net.URI;
import java.util.Date;
import java.util.List;

import com.uuah.config.UuahManifest;
import com.uuah.config.i18n.Message;
import com.uuah.config.i18n.MessageFactory;
import com.uuah.server.UuahServer;
import com.uuah.server.api.channel.IChannel;
import com.uuah.server.api.component.model.IEntryPointResolver;
import com.uuah.server.api.component.service.IService;
import com.uuah.server.api.config.IConfigurationBuilder;
import com.uuah.server.api.endpoint.IEndpointURI;
import com.uuah.server.api.endpoint.IUuahEndpoint;
import com.uuah.server.api.transformer.IBaseTransformer;
import com.uuah.server.api.transport.retry.RetryPolicyTemplate;
import com.uuah.server.exception.AbstractExceptionListener;
import com.uuah.utils.ClassUtils;
import com.uuah.utils.DateUtils;
import com.uuah.utils.StringUtils;

public class ServerMessages extends MessageFactory {
	private static final ServerMessages factory = new ServerMessages();

	private static final String BUNDLE_PATH = getBundlePath("server");

	public static Message versionNotSet() {
		return factory.createMessage(BUNDLE_PATH, 1);
	}

	public static Message serverStartedAt(long startDate) {
		return factory.createMessage(BUNDLE_PATH, 2, DateUtils
				.getStringFromDate(new Date(startDate), "yyyy-MM-dd HH:mm:ss"),
				(System.currentTimeMillis() - UuahServer.getStartTime()));
	}

	public static Message serverShutdownAt(Date date) {
		return factory.createMessage(BUNDLE_PATH, 3, date);
	}

	public static Message notSet() {
		return factory.createMessage(BUNDLE_PATH, 5);
	}

	public static Message version() {
		String version = StringUtils.defaultString(UuahManifest
				.getProductVersion(), notSet().getMessage());
		return factory.createMessage(BUNDLE_PATH, 6, version);
	}

	public static Message shutdownNormally(Date date) {
		return factory.createMessage(BUNDLE_PATH, 7, date);
	}

	public static Message serverWasUpForDuration(long duration) {
		String formattedDuration = DateUtils.getFormattedDuration(duration);
		return factory.createMessage(BUNDLE_PATH, 8, formattedDuration);
	}

	public static Message configNotFoundUsage() {
		return factory.createMessage(BUNDLE_PATH, 9);
	}

	public static Message fatalErrorWhileRunning() {
		return factory.createMessage(BUNDLE_PATH, 10);
	}

	public static Message rootStackTrace() {
		return factory.createMessage(BUNDLE_PATH, 11);
	}

	public static Message exceptionStackIs() {
		return factory.createMessage(BUNDLE_PATH, 12);
	}

	public static Message messageIsOfType(Class type) {
		return factory.createMessage(BUNDLE_PATH, 18, ClassUtils
				.getSimpleName(type));
	}

	public static Message fatalErrorInShutdown() {
		return factory.createMessage(BUNDLE_PATH, 20);
	}

	public static Message normalShutdown() {
		return factory.createMessage(BUNDLE_PATH, 21);
	}

	public static Message none() {
		return factory.createMessage(BUNDLE_PATH, 22);
	}

	public static Message notClustered() {
		return factory.createMessage(BUNDLE_PATH, 23);
	}

	public static Message failedToRouterViaEndpoint(IUuahEndpoint endpoint) {
		return factory.createMessage(BUNDLE_PATH, 30, endpoint);
	}

	public static Message cannotUseDisposedConnector() {
		return factory.createMessage(BUNDLE_PATH, 32);
	}

	public static Message connectorCausedError() {
		return connectorCausedError(null);
	}

	public static Message connectorCausedError(Object connector) {
		return factory.createMessage(BUNDLE_PATH, 33, connector);
	}

	public static Message endpointIsNullForListener() {
		return factory.createMessage(BUNDLE_PATH, 34);
	}

	public static Message listenerAlreadyRegistered(IEndpointURI endpointUri) {
		return factory.createMessage(BUNDLE_PATH, 35, endpointUri);
	}

	public static Message objectAlreadyInitialised(String name) {
		return factory.createMessage(BUNDLE_PATH, 37, name);
	}

	public static Message componentCausedErrorIs(Object component) {
		return factory.createMessage(BUNDLE_PATH, 38, component);
	}

	public static Message objectFailedToInitialise(String string) {
		return factory.createMessage(BUNDLE_PATH, 40, string);
	}

	public static Message failedToStop(String string) {
		return factory.createMessage(BUNDLE_PATH, 41, string);
	}

	public static Message failedToStart(String string) {
		return factory.createMessage(BUNDLE_PATH, 42, string);
	}

	public static Message componentNotRegistered(String name) {
		return factory.createMessage(BUNDLE_PATH, 46, name);
	}

	public static Message failedtoRegisterOnEndpoint(String name,
			Object endpointURI) {
		return factory.createMessage(BUNDLE_PATH, 47, name, endpointURI);
	}

	public static Message failedToUnregister(String name, Object endpointURI) {
		return factory.createMessage(BUNDLE_PATH, 48, name, endpointURI);
	}

	public static Message endpointIsMalformed(String endpoint) {
		return factory.createMessage(BUNDLE_PATH, 51, endpoint);
	}

	public static Message transformUnexpectedType(Class class1,
			Class returnClass) {
		return factory.createMessage(BUNDLE_PATH, 53, ClassUtils
				.getSimpleName(class1), ClassUtils.getSimpleName(returnClass));
	}

	public static Message transformOnObjectUnsupportedTypeOfEndpoint(
			String name, Class class1, IUuahEndpoint endpoint) {
		return factory.createMessage(BUNDLE_PATH, 54, name, StringUtils
				.toString(class1), (endpoint != null ? endpoint
				.getEndpointURI() : null));
	}

	public static Message transformFailedFrom(Class clazz) {
		return factory.createMessage(BUNDLE_PATH, 55, clazz);
	}

	public static Message failedToLoadTransformer(String direction,
			String transformer) {
		return factory.createMessage(BUNDLE_PATH, 57, direction, transformer);
	}

	public static Message failedToLoad(String string) {
		return factory.createMessage(BUNDLE_PATH, 58, string);
	}

	public static Message messageNotSupportedByAdapter(String string,
			String string2) {
		return factory.createMessage(BUNDLE_PATH, 59, string, string2);
	}

	public static Message noComponentForEndpoint() {
		return factory.createMessage(BUNDLE_PATH, 64);
	}

	public static Message failedToCreate(String string) {
		return factory.createMessage(BUNDLE_PATH, 65, string);
	}

	public static Object failedToDispose(String string) {
		return factory.createMessage(BUNDLE_PATH, 67, string);
	}

	public static Message failedToInvoke(String string) {
		return factory.createMessage(BUNDLE_PATH, 68, string);
	}

	public static Message cannotReadPayloadAsBytes(String type) {
		return factory.createMessage(BUNDLE_PATH, 69, type);
	}

	public static Message cannotReadPayloadAsString(String type) {
		return factory.createMessage(BUNDLE_PATH, 70, type);
	}

	public static Message routingFailedOnEndpoint(IService service,
			IUuahEndpoint endpoint) {
		IEndpointURI endpointURI = null;
		if (endpoint != null) {
			endpointURI = endpoint.getEndpointURI();
		}
		return factory.createMessage(BUNDLE_PATH, 72, service.getName(),
				endpointURI);
	}

	public static Message cannotInstanciateFinder(String serviceFinder) {
		return factory.createMessage(BUNDLE_PATH, 73, serviceFinder);
	}

	public static Message failedToCreateObjectWith(String string, Object arg) {
		return factory.createMessage(BUNDLE_PATH, 74, string, arg);
	}

	public static Message objectNotSetInService(Object object, Object service) {
		return factory.createMessage(BUNDLE_PATH, 75, object, service);
	}

	public static Message objectNotFound(String object) {
		return factory.createMessage(BUNDLE_PATH, 76, object);
	}

	public static Message objectNotFound(String type, String object) {
		return factory.createMessage(BUNDLE_PATH, 76, type + ": " + object);
	}

	public static Message noCurrentEventForTransformer() {
		return factory.createMessage(BUNDLE_PATH, 81);
	}

	public static Message objectNotRegistered(String type, String name) {
		return factory.createMessage(BUNDLE_PATH, 82, type, name);
	}

	public static Message failedToSetPropertiesOn(String string) {
		return factory.createMessage(BUNDLE_PATH, 83, string);
	}

	public static Message failedToCreateConnectorFromUri(IEndpointURI uri) {
		return factory.createMessage(BUNDLE_PATH, 84, uri);
	}

	public static Message failedToCreateEndpointFromLocation(String string) {
		return factory.createMessage(BUNDLE_PATH, 87, string);
	}

	public static Message noEndpointsForChannel() {
		return factory.createMessage(BUNDLE_PATH, 89);
	}

	public static Message responseTimedOutWaitingForId(int timeout, Object id) {
		return factory.createMessage(BUNDLE_PATH, 90, String.valueOf(timeout),
				id);
	}

	public static Message failedToRecevieWithTimeout(Object endpoint,
			long timeout) {
		return factory.createMessage(BUNDLE_PATH, 93, endpoint, String
				.valueOf(timeout));
	}

	public static Message failedToWriteMessageToStore(Object id,
			String storeName) {
		return factory.createMessage(BUNDLE_PATH, 94, id, storeName);
	}

	public static Message failedToReadFromStore(String absolutePath) {
		return factory.createMessage(BUNDLE_PATH, 95, absolutePath);
	}

	public static Message interruptedQueuingEventFor(Object object) {
		return factory.createMessage(BUNDLE_PATH, 106, object);
	}

	public static Message methodWithParamsNotFoundOnObject(String method,
			Object class1, Class class2) {
		return factory.createMessage(BUNDLE_PATH, 109, method, StringUtils
				.toString(class1), StringUtils.toString(class2));
	}

	public static Message transformFailed(String from, String to) {
		return factory.createMessage(BUNDLE_PATH, 110, from, to);
	}

	public static Message schemeNotCompatibleWithConnector(String scheme,
			Class expectedClass) {
		return factory.createMessage(BUNDLE_PATH, 115, scheme, expectedClass);
	}

	public static Message failedToReadPayload() {
		return factory.createMessage(BUNDLE_PATH, 124);
	}

	public static Message endpointNotFound(String endpoint) {
		return factory.createMessage(BUNDLE_PATH, 126, endpoint);
	}

	public static Message eventProcessingFailedFor(String name) {
		return factory.createMessage(BUNDLE_PATH, 127, name);
	}

	public static Message failedToClone(String string) {
		return factory.createMessage(BUNDLE_PATH, 145, string);
	}

	public static Message exceptionOnConnectorNotExceptionListener(String name) {
		return factory.createMessage(BUNDLE_PATH, 146, name);
	}

	public static Message uniqueIdNotSupportedByAdapter(String name) {
		return factory.createMessage(BUNDLE_PATH, 147, name);
	}

	public static Message serverNotificationManagerNotEnabled() {
		return factory.createMessage(BUNDLE_PATH, 150);
	}

	public static Message failedToScheduleWork() {
		return factory.createMessage(BUNDLE_PATH, 151);
	}

	public static Message valueIsInvalidFor(String value, String parameter) {
		return factory.createMessage(BUNDLE_PATH, 154, value, parameter);
	}

	public static Message connectorWithProtocolNotRegistered(String scheme) {
		return factory.createMessage(BUNDLE_PATH, 156, scheme);
	}

	public static Message propertyIsNotSupportedType(String property,
			Class expected, Class actual) {
		return factory.createMessage(BUNDLE_PATH, 157, property, StringUtils
				.toString(expected), StringUtils.toString(actual));
	}

	public static Message propertyIsNotSupportedType(String property,
			Class[] expected, Class actual) {
		return factory.createMessage(BUNDLE_PATH, 157, property, StringUtils
				.toString(expected), StringUtils.toString(actual));
	}

	public static Message containerAlreadyRegistered(String name) {
		return factory.createMessage(BUNDLE_PATH, 155, name);
	}

	public static Message reconnectStrategyFailed(Class strategy,
			String description) {
		return factory.createMessage(BUNDLE_PATH, 164, StringUtils
				.toString(strategy), description);
	}

	public static Message eventTypeNotRecognised(String string) {
		return factory.createMessage(BUNDLE_PATH, 166, string);
	}

	public static Message componentIsStopped(String name) {
		return factory.createMessage(BUNDLE_PATH, 167, name);
	}

	public static Message propertyIsNotSetOnEvent(String property) {
		return factory.createMessage(BUNDLE_PATH, 168, property);
	}

	public static Message descriptorAlreadyExists(String name) {
		return factory.createMessage(BUNDLE_PATH, 171, name);
	}

	public static Message transformOnObjectNotOfSpecifiedType(String name,
			Object expectedType) {
		return factory.createMessage(BUNDLE_PATH, 177, name, expectedType);
	}

	public static Message failedToBuildMessage() {
		return factory.createMessage(BUNDLE_PATH, 180);
	}

	public static Message propertiesNotSet(String string) {
		return factory.createMessage(BUNDLE_PATH, 183, string);
	}

	public static Message objectNotOfCorrectType(Class actualClass,
			Class[] expectedClass) {
		return factory.createMessage(BUNDLE_PATH, 185, StringUtils
				.toString(actualClass), StringUtils.toString(expectedClass));
	}

	public static Message objectNotOfCorrectType(Class actualClass,
			Class expectedClass) {
		return factory.createMessage(BUNDLE_PATH, 185, StringUtils
				.toString(actualClass), StringUtils.toString(expectedClass));
	}

	public static Message sessionValueIsMalformed(String string) {
		return factory.createMessage(BUNDLE_PATH, 201, string);
	}

	public static Message streamingFailedNoStream() {
		return factory.createMessage(BUNDLE_PATH, 205);
	}

	public static Message connectorSchemeIncompatibleWithEndpointScheme(
			Object expected, Object actual) {
		return factory.createMessage(BUNDLE_PATH, 206, expected, actual);
	}

	public static Message streamingNotSupported(String protocol) {
		return factory.createMessage(BUNDLE_PATH, 209, protocol);
	}

	public static Message moreThanOneConnectorWithProtocol(String protocol) {
		return factory.createMessage(BUNDLE_PATH, 221, protocol);
	}

	public static Message failedToGetOutputStream() {
		return factory.createMessage(BUNDLE_PATH, 223);
	}

	public static Message noEntryPointFoundForNoArgsMethod(
			final Object component, final String methodName) {
		return factory.createMessage(BUNDLE_PATH, 224, component, methodName);
	}

	public static Message noDelegateClassAndMethodProvidedForNoArgsWrapper() {
		return factory.createMessage(BUNDLE_PATH, 225);
	}

	public static Message noDelegateClassIfDelegateInstanceSpecified() {
		return factory.createMessage(BUNDLE_PATH, 226);
	}

	public static Message noServiceTransportDescriptor(String protocol) {
		return factory.createMessage(BUNDLE_PATH, 227, protocol);
	}

	public static Message failedToInvokeLifecycle(String phaseName,
			Object object) {
		return factory.createMessage(BUNDLE_PATH, 228, phaseName, object);
	}

	public static Message unrecognisedServiceType(String type) {
		return factory.createMessage(BUNDLE_PATH, 229, type);
	}

	public static Message requestChannelMustUseRequestEndpoints(
			IChannel channel, IUuahEndpoint endpoint) {
		return factory.createMessage(BUNDLE_PATH, 232, endpoint, channel);
	}

	public static Message exceptionListenerMustUseRequestEndpoint(
			AbstractExceptionListener exceptionListener, IUuahEndpoint endpoint) {
		return factory.createMessage(BUNDLE_PATH, 235, endpoint,
				exceptionListener);
	}

	public static Message productInformation() {
		String notset = ServerMessages.notSet().getMessage();
		return factory.createMessage(BUNDLE_PATH, 236, StringUtils
				.defaultString(UuahManifest.getProductDescription(), notset),
				StringUtils.defaultString(UuahManifest.getProductVersion(),
						notset), StringUtils.defaultString(UuahManifest
						.getVendorName(), notset)
						+ " "
						+ StringUtils.defaultString(UuahManifest.getVendorUrl(),
								notset));
	}

	public static Message noTransformerFoundForMessage(Class input, Class output) {
		return factory.createMessage(BUNDLE_PATH, 237, input.getName(), output
				.getName());
	}

	public static Message errorReadingStream() {
		return factory.createMessage(BUNDLE_PATH, 238);
	}

	public static Message noEntryPointFoundWithArgsUsingResolver(Object object,
			Object args, IEntryPointResolver resolver) {
		return factory.createMessage(BUNDLE_PATH, 240, StringUtils
				.toString(object), StringUtils.toString(args), resolver);
	}

	public static Message tooManyAcceptableMethodsOnObjectUsingResolverForTypes(
			Object object, Object types, IEntryPointResolver resolver) {
		return factory.createMessage(BUNDLE_PATH, 242, StringUtils
				.toString(object), StringUtils.toString(types), resolver);
	}

	public static Message objectDoesNotImplementInterface(Object object,
			Class interfaceClass) {
		return factory.createMessage(BUNDLE_PATH, 244, StringUtils
				.toString(object), interfaceClass);
	}

	public static Message invocationSuccessfulCantSetError() {
		return factory.createMessage(BUNDLE_PATH, 245);
	}

	public static Message noMatchingMethodsOnObjectCalledUsingResolver(
			Object object, String methodName, IEntryPointResolver resolver) {
		return factory.createMessage(BUNDLE_PATH, 246, StringUtils
				.toString(object), methodName, resolver);
	}

	public static Message noServiceQueueTimeoutSet(IService service) {
		return factory.createMessage(BUNDLE_PATH, 249, service);
	}

	public static Message failedToProcessExtractorFunction(String name) {
		return factory.createMessage(BUNDLE_PATH, 250, name);
	}

	public static Message expressionEvaluatorNotRegistered(String key) {
		return factory.createMessage(BUNDLE_PATH, 251, key);
	}

	public static Message objectAlreadyExists(String key) {
		return factory.createMessage(BUNDLE_PATH, 252, key);
	}

	public static Message objectAlreadyRegistered(String name,
			Object origObject, Object newObject) {
		return factory
				.createMessage(BUNDLE_PATH, 254, name, origObject + "."
						+ origObject.getClass(), newObject + "."
						+ newObject.getClass());
	}

	public static Message transformerNotImplementDiscoverable(
			IBaseTransformer transformer) {
		return factory.createMessage(BUNDLE_PATH, 255, transformer);
	}

	public static Message configurationBuilderSuccess(
			IConfigurationBuilder configurationBuilder, int numResources) {
		return factory.createMessage(BUNDLE_PATH, 257, configurationBuilder
				.getClass().getName(), new Integer(numResources));
	}

	public static Message configurationBuilderSuccess(
			IConfigurationBuilder configurationBuilder, String resources) {
		return factory.createMessage(BUNDLE_PATH, 258, configurationBuilder
				.getClass().getName(), resources);
	}

	public static Message configurationBuilderNoMatching(String resource) {
		return factory.createMessage(BUNDLE_PATH, 259, resource);
	}

	public static Message configurationBuilderError(
			IConfigurationBuilder configurationBuilder) {
		return factory.createMessage(BUNDLE_PATH, 260, StringUtils
				.toString(configurationBuilder.getClass()));
	}

	public static Message expressionEvaluatorReturnedNull(String name,
			String expr) {
		return factory.createMessage(BUNDLE_PATH, 263, name, expr);
	}

	public static Message expressionInvalidForProperty(String property,
			String expr) {
		return factory.createMessage(BUNDLE_PATH, 264, property, expr);
	}

	public static Message expressionMalformed(String expr, String eval) {
		return factory.createMessage(BUNDLE_PATH, 265, expr, eval);
	}

	public static Message correlationTimedOut(Object groupId) {
		return factory.createMessage(BUNDLE_PATH, 266, groupId);
	}

	public static Message transformerInvalidReturnType(Class clazz,
			String transformerName) {
		return factory.createMessage(BUNDLE_PATH, 267, clazz, transformerName);
	}

	public static Message failedToConnect(String what,
			RetryPolicyTemplate policy) {
		return factory.createMessage(BUNDLE_PATH, 272, what, policy);
	}

	public static Message notConnectedYet(String what) {
		return factory.createMessage(BUNDLE_PATH, 273, what);
	}

	public static Message stopPausedSedaServiceNonPeristentQueueMessageLoss(
			int num, IService service) {
		return factory.createMessage(BUNDLE_PATH, 274, num, service.getName());
	}

	public static Message splitMessageNoEndpointMatch(List endpoints,
			Object messagePart) {
		return factory.createMessage(BUNDLE_PATH, 275, StringUtils
				.toString(endpoints), messagePart);
	}

	public static Message expressionResultWasNull(String expression) {
		return factory.createMessage(BUNDLE_PATH, 276, expression);
	}

	public static Message failedToParseConfigResource(String description) {
		return factory.createMessage(BUNDLE_PATH, 277, description);
	}

	public static Message propertyTemplateMalformed(String string) {
		return factory.createMessage(BUNDLE_PATH, 278, string);
	}

	public static Message systemPropertyNotSet(String property) {
		return factory.createMessage(BUNDLE_PATH, 279, property);
	}

	public static Message mustSpecifyContainerRefOrClassAttribute(
			String containerAttrib, String refAttrib, String config) {
		return factory.createMessage(BUNDLE_PATH, 280, containerAttrib,
				refAttrib, config);
	}

	public static Message requestFailedWithStatus(String string) {
		return factory.createMessage(BUNDLE_PATH, 281, string);
	}

	public static Message unableToGetEndpointUri(String requestURI) {
		return factory.createMessage(BUNDLE_PATH, 282, requestURI);
	}

	public static Message receiverPropertyNotSet() {
		return factory.createMessage(BUNDLE_PATH, 283);
	}

	public static Message httpParameterNotSet(String string) {
		return factory.createMessage(BUNDLE_PATH, 284, string);
	}

	public static Message malformedSyntax() {
		return factory.createMessage(BUNDLE_PATH, 285);
	}

	public static Message methodNotAllowed(String method) {
		return factory.createMessage(BUNDLE_PATH, 286, method);
	}

	public static Message failedToConnect(URI uri) {
		return factory.createMessage(BUNDLE_PATH, 287, uri);
	}

	public static Message cannotBindToAddress(String path) {
		return factory.createMessage(BUNDLE_PATH, 288, path);
	}

	public static Message eventPropertyNotSetCannotProcessRequest(
			String property) {
		return factory.createMessage(BUNDLE_PATH, 289, property);
	}

	public static Message unsupportedMethod(String method) {
		return factory.createMessage(BUNDLE_PATH, 290, method);
	}

	public static Message couldNotSendExpect100() {
		return factory.createMessage(BUNDLE_PATH, 291);
	}

	public static Message requestLineIsMalformed(String line) {
		return factory.createMessage(BUNDLE_PATH, 292, line);
	}

	public static Message pollingReciverCannotbeUsed() {
		return factory.createMessage(BUNDLE_PATH, 293);
	}

	public static Message failedToBindToUri(URI uri) {
		return factory.createMessage(BUNDLE_PATH, 301, uri);
	}

	public static Message failedToCloseSocket() {
		return factory.createMessage(BUNDLE_PATH, 302);
	}

}
